package com.ae.content.web;

import com.ae.content.dto.ReturnModel;
import com.ae.content.enums.ReturnCodeEnum;
import com.global.iop.api.IopClient;
import com.global.iop.api.IopClientImpl;
import com.global.iop.api.IopRequest;
import com.global.iop.api.IopResponse;
import com.global.iop.domain.Protocol;
import com.global.iop.util.ApiException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/health")
@ResponseBody
public class HealthController {

    @GetMapping("/health")
    public ReturnModel health() throws ApiException, InterruptedException {
        IopClient client = new IopClientImpl("https://api-sg.aliexpress.com", "504368", "9YXgCPaIN7iu5AISehgpNRoHiiwRmGXw");
        IopRequest request = new IopRequest();
        request.setApiName("aliexpress.influencer.content.video.publish");
        request.addApiParameter("request_param", "{\"video_resource_id\":\"12321321321\",\"external_items\":[{\"item_main_pic\":\"xxxx\",\"item_price\":\"$+12.34\",\"item_url\":\"xxx\",\"source\":\"TT\",\"item_pics\":[\"[\\\"xxxx\\\",\\\"xxxx\\\"]\",\"[\\\"xxxx\\\",\\\"xxxx\\\"]\"],\"title\":\"test+Product\"},{\"item_main_pic\":\"xxxx\",\"item_price\":\"$+12.34\",\"item_url\":\"xxx\",\"source\":\"TT\",\"item_pics\":[\"[\\\"xxxx\\\",\\\"xxxx\\\"]\",\"[\\\"xxxx\\\",\\\"xxxx\\\"]\"],\"title\":\"test+Product\"}],\"hashtags\":[{\"object_type\":\"0\",\"start\":\"101\",\"end\":\"110\",\"object_id\":\"12321\",\"content\":\"HomeDecor\"},{\"object_type\":\"0\",\"start\":\"101\",\"end\":\"110\",\"object_id\":\"12321\",\"content\":\"HomeDecor\"}],\"currency\":\"USD\",\"attributes\":{\"K1\":\"V1\"},\"locale\":\"en_US\",\"items\":[{\"item_id\":\"10031731496\"},{\"item_id\":\"10031731496\"}],\"content\":\"Good+Day!\\\\n\\\\nPrepare+For+Halloween,+Coat+Hook+Rack+On+Wall+\\\\n\\\\nWith+Installation+Screws,+Fast+Shipping+\\\\n#HomeDecor\\\\n\\\\n\\\\n\",\"email\":\"heyuting0714@gmail.com\",\"cover_img_resource_id\":\"7044701919259020\"}");
        IopResponse response = client.execute(request, Protocol.TOP);
        System.out.println(response.getGopResponseBody());
        Thread.sleep(10);
        return new ReturnModel(ReturnCodeEnum.getCode("success"), "success", "");
    }

}
